package com.feishi.core.analytic.body;

import com.feishi.core.util.common.bean.ByteBufferProxy;
import com.feishi.core.analytic.assembler.BaseAssembler;
import com.feishi.core.analytic.element.AnalyticElement;
import com.feishi.core.analytic.packing.AnalyticBuildPacking;
import com.feishi.core.analytic.packing.AnalyticDataPacking;
import com.feishi.core.analytic.packing.AnalyticUnPacking;
import com.feishi.core.analytic.packing.build.BuildConfig;
import com.feishi.core.analytic.packing.debuild.DeBuildConfig;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by caixq on 4/27 027.
 */
public class AnalyticBody {
    private String name;
    private List<AnalyticElement> elements=new ArrayList<>();
    public Class<? extends BaseAssembler> classz;

    public BuildConfig buildConfig=BuildConfig.getInstance();
    public DeBuildConfig debuildConfig=DeBuildConfig.getInstance();
    public char escapeCode;
    public char separatorCode;
    public int unpackingMode=0;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<AnalyticElement> getElements() {
        return elements;
    }

    public void setElements(List<AnalyticElement> elements) {
        this.elements = elements;
    }

    private AnalyticUnPacking analyticUnPacking;

    public AnalyticUnPacking analyticUnPacking(){
        return this.analyticUnPacking!=null?analyticUnPacking:(this.analyticUnPacking=new AnalyticUnPacking(this));
    }
    private AnalyticBuildPacking analyticBuildPacking;

    public AnalyticBuildPacking analyticBuildPacking(){
        return this.analyticBuildPacking!=null?analyticBuildPacking:(this.analyticBuildPacking=new AnalyticBuildPacking(this));
    }

    public void addElement(AnalyticElement analyticElement) {
        elements.add(analyticElement);
    }

    public byte[] tryToGetBody(ByteBufferProxy bfp) throws IOException {
        return analyticUnPacking().tryToGetBody(bfp);
    }
    public AnalyticDataPacking deBuild(byte[] bytes)  {
        AnalyticDataPacking packing = analyticBuildPacking().analyticDataPacking();
        packing.deBuild(bytes);
        return packing;
    }

}
